package com.example.pictureview;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class tupianliulan extends AppCompatActivity {
    ImageView img = null;
    Button but = null;
    Button fh;
    private Animation mAnimation;
    int count = 0;
    int[] imgRes = {R.drawable.dog1,R.drawable.dog2,R.drawable.dog3,R.drawable.dog4,
                    R.drawable.cat1,R.drawable.cat2,R.drawable.cat3,R.drawable.cat4};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tupianliulan);

        Bitmap bm = BitmapFactory.decodeResource(this.getResources(),imgRes[count]);
        img = (ImageView)findViewById(R.id.imageView);
        but = (Button)findViewById(R.id.but_next);
        img.setImageBitmap(bm);
        fh=findViewById(R.id.fh);
        fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(tupianliulan.this,MainActivity.class);
                startActivity(intent);
            }
        });


        but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                count++;
                if (count == 8) {
                    count = 0;
                }
                BitmapFactory.Options opt = new BitmapFactory.Options();
                opt.inSampleSize = 2;                   /*2陪缩放图片*/
                opt.inDither = false;                     /*不进行图片抖动处理*/
                opt.inPreferredConfig = null;             /*设置让解码器以最佳方式解码*/
                Bitmap bm2 = BitmapFactory.decodeResource(tupianliulan.this.getResources(), imgRes[count], opt);
                img.setImageBitmap(bm2);
                //动画渐变切换图片
                mAnimation = AnimationUtils.loadAnimation(tupianliulan.this,
                        R.anim.my_alpha);
                img.startAnimation(mAnimation);
            }
        });

    }
}

